<?php
/**
 * @Author: lianlianzan(13040@qq.com)
 * @Date:   2018-08-18 16:40:16
 * @Last Modified by:   lianlianzan
 * @Last Modified time: 2020-11-08 10:11:37
 */

namespace app\admin\controller;
use app\common\controller\Backend;

class AuthCate extends Backend {

	function initialize() {
		parent::initialize();
		$this->saveAndGetConfigIdentify('', '菜单分类', '', 'authCate');

		$this->authCateDao = model('admin/AuthCate');
	}

	public function index() {
		$map = $parameter = array();

		//获取所有的菜单类目
		list($list) = $this->authCateDao->search($map, '');
		$this->assign('list', $list);

		return $this->fetch();
	}

	public function listorders() {
		$result = parent::listordersOrigin($this->authCateDao);
		if ($result !== false) {
			$this->success('排序更新成功');
		} else {
			$this->error('排序更新失败');
		}
	}

	public function add() {
		$id = input('param.id', '', 'intval');

		if ($id) {
			$info = $this->authCateDao->getInfo($id);
		}
		//print_r($info);
		$this->assign('id', $id);
		$this->assign('info', $info);

		return $this->fetch();
	}

	public function doAdd() {
		$id = input('post.id', '', 'intval');
		$data = input('post.data/a', '', 'pwEscape');

		if ($id) {
			$info = $this->authCateDao->get($id);
		}

		if ($id) {
			$result = $this->authCateDao->baseUpdateData($id, $data);
			if ($result !== false) {
				$this->success('保存成功', url('admin/authCate/index'));
			} else {
				$this->error('保存失败'.showDbError($this->authCateDao));
			}
		} else {
			$result = $this->authCateDao->baseAddData($data);
			if ($result !== false) {
				$this->success('添加成功', url('admin/authCate/index'));
			} else {
				$this->error('添加失败'.showDbError($this->authCateDao));
			}
		}
	}

	public function doDelete() {
		$id = input('param.id', '', 'intval');

		if ($id) {
			$info = $this->authCateDao->get($id);
		}

		$result = $this->authCateDao->del($id);
		if ($result !== false) {
			$this->success('删除成功', url('admin/authCate/index'));
		} else {
			$this->error('删除失败'.showDbError($this->authCateDao));
		}
	}

}